package com.experiment.aicommunityback.util;

import com.experiment.aicommunityback.entity.RUutil;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author 杨婉汐
 * @name someUntil
 * @Date 2024/12/23  17:37
 */
public class RoleCompare {
    /**
     * role比较规则
     */
    public static int getRolePriority(String rolename) {
        switch (rolename) {
            case "root":
                return 3;
            case "normal":
                return 2;
            case "test":
                return 1;
            default:
                return 0;
        }
    }

    public static List<RUutil> getBigRole(List<RUutil> list){
        List<RUutil> ruList = new ArrayList<>(list.stream()
                .collect(Collectors.toMap(RUutil::getUserName, Function.identity(), BinaryOperator.maxBy(Comparator.comparing(ru -> getRolePriority(ru.getRoleName())))))
                .values());
        return ruList;
    }
}
